package com.hackerrank.contests.quantium.challenges.kmismatch;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Solution {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int K = in.nextInt(), C = 0;
		in.nextLine();
		char ch[] = in.nextLine().toCharArray();
		for(int i = 1; i < ch.length; i++) {
			Queue<Integer> q = new LinkedList<Integer>();
			q.add(-1);
			for(int j = 0; j < ch.length - i; j++) {
				if(ch[i + j] != ch[j]) {
					if(q.size() > K)
						q.remove();
					q.add(j);
				}
				C += j - q.peek();
			}
		}
		System.out.println(C);
	}
}
